import type { AppContext, ExtractPropTypes, VNode } from "vue"

export const bDialogProps = {
  id: {
    type: String,
    required: true,
  },
  title: String,
  Comp: {
    type: Object,
  },
  CompParams: {
    type: Object,
  },
  zIndex: Number,
  width: {
    type: Number,
    default: 300,
  },
  height: {
    type: Number,
    default: 200,
  },
  left: {
    type: Number,
    default: 150,
  },
  top: {
    type: Number,
    default: 20,
  },
  onClose: Function,
  hideTools: {
    type: Boolean,
    default: false,
  }
} as const

export type BDialogProps = ExtractPropTypes<typeof bDialogProps>


export type BDialogOptions = Omit<BDialogProps, 'id'> & {
  appendTo?: HTMLElement | string
}

export type BDialogParams = Partial<BDialogOptions> | string | VNode

export interface BDialogHandle {
  close: () => void,
}

export type BDialogFn = ((
  options?: BDialogParams,
  appContext?: null | AppContext
) => BDialogHandle) & {
  close: (id: string, userOnClose?: (vm: VNode) => void, res?: any) => void
  closeAll (): void
  recoverZindex(): void
}

export interface BDialog extends BDialogFn { }

interface BDialogQueueItem {
  vm: VNode
  el: Node
}
export type BDialogQueue = BDialogQueueItem[]
